module.exports = function ($scope, $state, $resource,$modal, $timeout, $stateParams, toaster) {

  /* 分页
      * ========================================= */
      $scope.maxSize = 5;            //最多显示多少个按钮
      $scope.bigCurrentPage = 1;      //当前页码
      $scope.itemsPerPage = 10;         //每页显示几条
      $scope.searchform = {};
    
      $scope.load = function () {
          var para = {
            guide_name:$scope.searchform.guide_name,
            pageNo: $scope.bigCurrentPage,
            pageSize: $scope.itemsPerPage
          };
          para = angular.extend($scope.searchform, para);
          $resource('/api/as/ggc/tourgroupafter/findGuidepageList', {}, {}).save(para,function (res) {
    
            if (res.errcode !== 0) {
              alert("数据获取失败");
              return;
            }
      
            $scope.objs = res.data.results;
            $scope.bigTotalItems = res.data.totalRecord;
            $scope.bigCurrentPage = res.data.pageNo;
      
          });
      };
    $scope.load();




    $scope.del = function (code) {
      if(confirm("您确认要删除吗？")){
      $resource('/api/as/ggc/tourgroupafter/updateDelGuide', {}, {}).save({'guide_code':code},function (res) {
        if (res.errcode === 0) {
          toaster.success({ title: "提示", body: "删除成功！"});
          $scope.load();
        } else {
          toaster.error({ title: "提示", body: res.errmsg });
        }
      });
    }
    }

    $scope.repswd = function(guide_code) {
      if(confirm("您确认要重置当前导游的密码为“123456”吗？")){
        $resource('/api/as/ggc/tourgroupafter/updateGuideRePswdOneTwoThree', {}, {}).save({'guide_code':guide_code},function (res) {
          if (res.errcode === 0) {
            toaster.success({ title: "提示", body: "重置成功！"});
            $scope.load();
          } else {
            toaster.error({ title: "提示", body: res.errmsg });
          }
        });
      }
    }

    $scope.add = function(guide_code){
      var modalInstance = $modal.open({
          template: require('../views/addguide.html'),
          controller: 'addguide',
          size: 'xs',
          resolve: {
            guide_code:function(){
              return guide_code;
            },
            flag : function () {
              return guide_code == 1;
            }
          }
      });
      modalInstance.result.then(function (showResult) {	
        $scope.load();
      });
      
  };
  $scope.update = function(guide_code){
    console.log('fdsa');
    var modalInstance = $modal.open({
        template: require('../views/addguide.html'),
        controller: 'addguide',
        size: 'xs',
        resolve: {
            guide_code:function(){
              return guide_code;
            },
            flag : function () {
              return guide_code == 1;
            }
        }
    });
    modalInstance.result.then(function (showResult) {	
      $scope.load();
    });
    
};


  // $scope.lookpt = function(code){
  //   $state.go('app.presettrajectory',{'tcode' : code});
  // }
  // $scope.lookpr = function(code){
  //   $state.go('app.practrcal',{'tcode' : code});
  // }
}